﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Minestorm.Retro
{
    public class Constants
    {
        static Constants()
        {
            VectorColor = new Color(136, 235, 213);
        }

        public static Color VectorColor { get; private set; }

        public class Ship
        {
            public const float Scale = .5f;
            public const float MaxThrustIncrement = .05f;
            public const float MaxSpeed = .25f;
            public const float DecelerationRate = .015f;

            public const float BulletSpeed = 1f;
            public const float BulletScale = 3f;
            public const float BulletOffset = .8f;

            private const int BulletLife = 700;

            public static TimeSpan BulletLifeTimespan = TimeSpan.FromMilliseconds(BulletLife);
        }

        public class Mine
        {
            public const float Enemy_Speed = .06f;
            public const float Float_Speed = .06f;
            public const float Fireball_Speed = .3f;

            public const int ExplosionMinLines = 8;
            public const int ExplosionMaxLines = 16;
            public const float ExplosionLineLength = .5f;
        }

        public class Dropdship
        {
            public const float MovementStep = -.15f;
            public const float ScaleStep = -.003f;
            public const float MinScale = .0001f;
        }

        public class Star
        {
            public const float DeploySpeed = .15f;
        }

        public class Level
        {
            //public const int MinX = -34;
            //public const int MaxX = 34;
            public const int MinX = -14;
            public const int MaxX = 14;

            public const int MinY = -17;
            public const int MaxY = 19;

            public const int SpawnMargin = 2;

            private const int SpawnInterval = 1000;
            private const int SpawnStart = 1000;
            private const int DeadTimeout = 2000;
            private const int WinTimeout = 3000;

            public static TimeSpan SpawnIntervalTimespan = TimeSpan.FromMilliseconds(SpawnInterval);
            public static TimeSpan DeadTimeoutTimespan = TimeSpan.FromMilliseconds(DeadTimeout);
            public static TimeSpan WinTimeoutTimespan = TimeSpan.FromMilliseconds(WinTimeout);
            public static TimeSpan SpawnStartTimespan = TimeSpan.FromMilliseconds(SpawnStart);
        }
    }

    public static class RandomHelper
    {
        static RandomHelper()
        {
            Random = new Random();
        }

        public static Random Random { get; private set; }

        public static bool Bool()
        {
            return Random.Next(0, 2) == 1;
        }

        public static Vector2 MineLayerSpawn()
        {
            switch (Random.Next(4))
            {
                case 0:
                    return new Vector2(Constants.Level.MinX - 2, 0f);
                case 1:
                    return new Vector2(Constants.Level.MaxX + 2, 0f);
                case 2:
                    return new Vector2(0f, Constants.Level.MinY - 2);
                case 3:
                    return new Vector2(0f, Constants.Level.MaxY + 2);
            }

            return new Vector2(Constants.Level.MinX - 2, 0f);
        }

        public static T GetElement<T>(T[] array)
        {
            return array[Random.Next(array.Length)];
        }

        public static Vector2 GetVectorWithinBounds()
        {
            return new Vector2(Random.Next(Constants.Level.MinX, Constants.Level.MaxX), Random.Next(Constants.Level.MinY, Constants.Level.MaxY));
        }

        public static Vector2 GetSpawnVectorWithinBounds()
        {
            return new Vector2(Random.Next(Constants.Level.MinX + Constants.Level.SpawnMargin, Constants.Level.MaxX - Constants.Level.SpawnMargin), Random.Next(Constants.Level.MinY + Constants.Level.SpawnMargin, Constants.Level.MaxY - Constants.Level.SpawnMargin));
        }

        public static float GetAngle()
        {
            return MathHelper.ToRadians(Random.Next(360));
        }

        public static int GetExplosionLineCount()
        {
            return Random.Next(Constants.Mine.ExplosionMinLines, Constants.Mine.ExplosionMaxLines);
        }

        public static Vector3 GetExplosionLineVector()
        {
            return new Vector3((float)Random.NextDouble() - .5f, (float)Random.NextDouble() - .5f, (float)Random.NextDouble() - .5f);
        }
    }
}
